
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :chengbiao.he
	CreateTime:2008-02-22 10:35:17
*/
public class ServerDownupfileInfoSrv extends IHandler
{

	public ServerDownupfileInfoSrv() 
	{
		super();
	}
	private void deleteServerDownupfileInfo(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		ServerDownupfileInfo obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = ServerDownupfileInfo.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveServerDownupfileInfo(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		ServerDownupfileInfo obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = ServerDownupfileInfo.fetch();
    	}
    	else                     //update
    	{
    		obj = ServerDownupfileInfo.fetch(con,id);
    	}
		ServerDownupfileInfoPageData data = (ServerDownupfileInfoPageData)PageData.fromForm(context,ServerDownupfileInfoPageData.class);
		context.setValue("ServerDownupfileInfoPageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listServerDownupfileInfo(DBConnection con,SrvContext context,ILoginContext loginContext,String path) throws Exception
	{
		ServerDownupfileInfoSearchEvent event = (ServerDownupfileInfoSearchEvent)SearchEvent.fromForm(context,ServerDownupfileInfoSearchEvent.class);
		event.setWarehouseCodeUser(ConstDefine.getWildCard(loginContext.getLoginWarehouseCode()));
		context.setSessionValue("ServerDownupfileInfoSearchEvent",event);
		context.setNextUrl(path+"ServerDownupfileInfoList.jsp");
	}
	private void backServerDownupfileInfo(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"ServerDownupfileInfoList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listServerDownupfileInfo"))
		{
			listServerDownupfileInfo(con,context,loginContext,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewServerDownupfileInfo"))
		{
			String id = context.getString("Id",null);
			ServerDownupfileInfo obj = ServerDownupfileInfo.fetch(con,id);
			context.setValue("ServerDownupfileInfo",obj);
			context.setNextUrl(path+"ServerDownupfileInfoView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteServerDownupfileInfo"))
		{
			context.setErrorUrl(path+"ServerDownupfileInfoList.jsp");
			deleteServerDownupfileInfo(con,context);
			backServerDownupfileInfo(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddServerDownupfileInfo"))
		{
			ServerDownupfileInfo obj = ServerDownupfileInfo.fetch();
			ServerDownupfileInfoPageData data = (ServerDownupfileInfoPageData)PageData.fromTable(obj,ServerDownupfileInfoPageData.class);
			context.setValue("ServerDownupfileInfoPageData",data);
			context.setNextUrl(path+"ServerDownupfileInfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateServerDownupfileInfo"))
		{
			String id = context.getString("Id",null);
			ServerDownupfileInfo obj = ServerDownupfileInfo.fetch(con,id);
			ServerDownupfileInfoPageData data = (ServerDownupfileInfoPageData)PageData.fromTable(obj,ServerDownupfileInfoPageData.class);
			context.setValue("ServerDownupfileInfoPageData",data);
			context.setNextUrl(path+"ServerDownupfileInfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyServerDownupfileInfo"))
		{
			String id = context.getString("Id",null);
			ServerDownupfileInfo obj = ServerDownupfileInfo.copy(ServerDownupfileInfo.fetch(con,id));
			ServerDownupfileInfoPageData data = (ServerDownupfileInfoPageData)PageData.fromTable(obj,ServerDownupfileInfoPageData.class);
			context.setValue("ServerDownupfileInfoPageData",data);
			context.setNextUrl(path+"ServerDownupfileInfoEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveServerDownupfileInfo"))
		{
			context.setErrorUrl(path+"ServerDownupfileInfoEdit.jsp");
			saveServerDownupfileInfo(con,context,loginContext);
			backServerDownupfileInfo(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewServerDownupfileInfo"))
		{
			context.setErrorUrl(path+"ServerDownupfileInfoEdit.jsp");
			saveServerDownupfileInfo(con,context,loginContext);
			ServerDownupfileInfo obj = ServerDownupfileInfo.fetch();
			ServerDownupfileInfoPageData data = (ServerDownupfileInfoPageData)PageData.fromTable(obj,ServerDownupfileInfoPageData.class);
			context.setValue("ServerDownupfileInfoPageData",data);
			context.setNextUrl(path+"ServerDownupfileInfoEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListServerDownupfileInfo"))
		{
			backServerDownupfileInfo(con,context,path);
			return;
		}
		
		//add by chengbiao.he start

		//add by chengbiao.he end

		Logger.throwException("ServerDownupfileInfoSrv","unknown action_code="+action_code);
	}
}
